package com.ruiben.mall.controller;


import com.ruiben.mall.impl.SearchServiceImpl;
import com.ruiben.mall.pojo.ShopProduct;
import com.ruiben.mall.utils.CommonJSONResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("search")
public class SearchController extends BaseController {


    @Autowired
    private SearchServiceImpl searchService;

    @PostMapping("searchGoods")
    public CommonJSONResult searchGoods(String goodsName,Integer sort){

        if (sort == null){
            sort = 1;
        }

        List<ShopProduct> shopProducts = searchService.searchGoods(goodsName,sort);
        return CommonJSONResult.ok(shopProducts);

    }

}
